unit uniSaidaMateriais;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, Mask, DBCtrls, StdCtrls, Buttons, ExtCtrls, DB,
  ADODB;

type
  TfrmSaidaMateriais = class(TForm)
    Panel2: TPanel;
    btnFechar: TSpeedButton;
    btnIncluir: TSpeedButton;
    Panel3: TPanel;
    Label2: TLabel;
    btnPesquisa: TSpeedButton;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    edtPedido: TEdit;
    dblCliente: TDBLookupComboBox;
    edtDtInicial: TMaskEdit;
    edtDtFinal: TMaskEdit;
    Panel4: TPanel;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    DBGrid2: TDBGrid;
    SpeedButton3: TSpeedButton;
    QR_Cliente: TADOQuery;
    DS_Cliente: TDataSource;
    QR_Grid1: TADOQuery;
    DS_Grid1: TDataSource;
    QR_Grid1CD_PEDIDO: TWideStringField;
    QR_Grid1DATA: TDateTimeField;
    QR_Grid1CD_CLIENTE: TIntegerField;
    QR_Grid1DS_CLIENTE: TStringField;
    QR_Grid2: TADOQuery;
    DS_Grid2: TDataSource;
    QR_Grid1CD_PREVISAO_ENTREGA: TAutoIncField;
    QR_Grid1QUANTIDADE: TIntegerField;
    procedure FormShow(Sender: TObject);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnFecharClick(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSaidaMateriais: TfrmSaidaMateriais;

implementation

uses uniCadMovimentacaoEstoque, uniCadPedido;

{$R *.dfm}

procedure TfrmSaidaMateriais.FormShow(Sender: TObject);
begin
  QR_Cliente.Close;
  QR_Cliente.Open;
  QR_Grid1.Close;
  QR_Grid1.Open;
  QR_Grid2.Close;
  QR_Grid2.Open;
end;

procedure TfrmSaidaMateriais.btnIncluirClick(Sender: TObject);
begin
  //Chama a tela de saida de materiais com a operacao de saida
  try
   Application.CreateForm(TfrmCadMovimentacaoEstoque, frmCadMovimentacaoEstoque);
   frmCadMovimentacaoEstoque.gOperacao := 'S';
   frmCadMovimentacaoEstoque.gCdPrevisaoEntrega := QR_Grid1.FieldByName('CD_PREVISAO_ENTREGA').AsString;

   frmCadMovimentacaoEstoque.ShowModal;
  finally
    frmCadMovimentacaoEstoque.Free;
  end;         
end;

procedure TfrmSaidaMateriais.btnFecharClick(Sender: TObject);
begin
Close;
end;

procedure TfrmSaidaMateriais.SpeedButton3Click(Sender: TObject);
begin
 if not (QR_Grid1.Active) then
    exit;
  try
    Application.CreateForm(TfrmCadPedido, frmCadPedido);
    frmCadPedido.sEstado := 'V';
    frmCadPedido.sCdCampo := QR_Grid1.FieldByName('cd_pedido').AsString;
    frmCadPedido.ShowModal;
  finally
     frmCadPedido.Free;
  end;
end;

end.
